﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

public partial class Passward : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //Check if input is validated
        if(TextBox1.Text == "" || TextBox2.Text == "")
        {
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "输入不能为空！";
        }
        //Check if the length is > 6
        if(TextBox1.Text.Length < 6)
        {
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "密码长度大于6！";
        }
        //Check if equal
        if(String.Compare(TextBox1.Text, TextBox2.Text) != 0)
        {
            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "输入密码不一致！";
        }
        else
        {
            StaffDB db = new StaffDB();
            string UserName = (string)Session[Engine.m_Usnkey];
            UserGroup curGroup = (UserGroup)Session[Engine.m_Usgkey];
            if (curGroup == UserGroup.Admin
             || curGroup == UserGroup.Assitant
             || curGroup == UserGroup.Safety)
            {
                db.UpdateAdminPwd(UserName,TextBox1.Text);
            }
            else
            {
                db.UpdateStaffPwd(UserName,TextBox1.Text);
            }
            

            ((Label)Page.Master.FindControl("ErrorLabel")).Text = "密码修改成功！";
            ((Label)Page.Master.FindControl("ErrorLabel")).ForeColor = Color.Green;
        }


    }
}
